$(
function(){
     $("#reg_confrim_close").hide();
     
     $("#reg_confrim_div_step2").hide();
     $("#reg_confrim_div_step3").hide();
     
     $("#reg_step_1").click(function() {
	 	var password  = $("#reg-confrim-pass").val() ;
		var password1  = $("#reg-confrim-pass1").val() ;
		if (password=="" || password.length<6){
			var errorMsg = '请输入至少6位的密码';
			$("#password-error").text(errorMsg) ;
			return false ;
		}
		if (password != password1){
			var errorMsg = '两次输入密码不一致';
            $("#password-error").text(errorMsg) ;
			return false ;
		}
		
		$("#password").val(password);
		$("#password1").val(password1);
		
        $("#reg_confrim_div_step1").hide();
        $("#reg_confrim_div_step2").show();
		$("#reg-confrim-nickname").focus();
     });
	 
	 
	  $("#reg-confrim-nickname").blur(function(){
	  	    var txt_value =  $(this).val();
			var $error_message = $("#error_message") ;
			if (txt_value==""||txt_value.length<2){
				$error_message.text("请输入您的昵称");
			} else{
				$.AiddAjax({
					type:"GET",
					href:"/ajax/?method=check_nickname",
					param:"nickname="+txt_value
				},function(data){
					if (data.code==1){
						$error_message.text("恭喜您,昵称可用");
					}else{
						$error_message.text("昵称不可用");
					};
				});
			}
	  }) ;
	  
	  
	$("#sex-man").click(function() {
		$("#gentle").val(1);
     });
	 
	$("#sex-women").click(function() {
		$("#gentle").val(0);
     });
     
     $("#reg_step_2").click(function() {
	 	var nickname  = $("#reg-confrim-nickname").val();
		var $error_message = $("#error_message") ;
		
		if (nickname==""){
			var errorMsg = '请输入您的昵称!';
			$error_message.text(errorMsg) ;
			return false ;
		}
		
		$("#nickname").val(nickname);
				
		alert($("#gentle").val());
		

		var password  = $("#password").val() ;
		var password1  = $("#password1").val() ;
		
		
		if (password=="" || password.length<6){
			var errorMsg = '请输入至少6位的密码';
			$error_message.text(errorMsg) ;
			return false ;
		}
		if (password!=password1){
			var errorMsg = '两次密码不一致';
			$error_message.text(errorMsg) ;
			return false ;
		}
		
		$.AiddAjax({
				type:"POST",
				href:"/confirmregister/",
				param: $("#regist-confrim-form").serialize() + "&_xsrf=" + $.getCookie("_xsrf"),
			},function(data){
				if (data.code==1){
					$("#reg_confrim_div_step2").hide();
					$("#reg_confrim_div_step3").show();
        			$("#reg_confrim_close").show();
				}else{
					$error_message.text(data.message);
				};
			});
     });
     
     $("#reg_confrim_close").click(function() {

        $("#reg_confrim_div_step3").hide();
		window.location = "/";
     });
	 $("#file_form").ajaxForm({
		type : "POST",
		success : function(d) {
			alert(d.url);
			$("#avaterArea").empty().append('<img src="' + d.url + '" width="186" height="186"/>');
		} ,
		dataType : "json",
		error:function(d) {
						
		}		
	 });
	 $("#user-face-img").change(function() {
		var val = this.value;
		if(val) {
			$("#file_form").submit();		
		}		
	 });
	   
});